//
//  LDRTRootNavVC.swift
//  DingDongZP
//
//  Created by 三秒文化 on 16/7/28.
//  Copyright © 2016年 51ledian.com. All rights reserved.
//

import UIKit

//class LDCustomRootNavVC: RTRootNavigationController {
//
//    private var barLeft:UIBarButtonItem?
//    
//    override func viewDidLoad() {
//        super.viewDidLoad()
//
//        interactivePopGestureRecognizer!.enabled = true
//        interactivePopGestureRecognizer!.delegate = nil
//        //左bar图
//        barLeft = UIBarButtonItem(image: UIImage(named:"navBack.png"), style: UIBarButtonItemStyle.Plain, target: self, action:#selector(self.navBack))
//    }
//    
//    override  func pushViewController(viewController: UIViewController, animated: Bool) {
//        
//        
//        super.pushViewController(viewController, animated: animated)
//        if self.childViewControllers.count > 0 {
//            
//            viewController.navigationItem.leftBarButtonItem = barLeft
//        }
//        
//        
////        navigationBar.barTintColor = LDGolbalColor.Green
////        navigationBar.tintColor = UIColor.whiteColor()
//        
////        super.pushViewController(viewController, animated: true)
//    }
//    
//    
//    func navBack() {
//        
//        popViewControllerAnimated(true)
//    }
//}


class LDRTRootNavVC: RTRootNavigationController {
    
    private var tapBackColure:(()->Void)?
    private var tapPushClosure:(()->Void)?
    private var barLeft:UIBarButtonItem?
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        interactivePopGestureRecognizer!.enabled = true
        interactivePopGestureRecognizer!.delegate = nil
        
        navigationBar.barTintColor = LDGolbalColor.Green
        navigationBar.tintColor = UIColor.whiteColor()
        
        //        let image = UIImage.setImageWithColor(LDGolbalColor.Green.colorWithAlphaComponent(1))
        //        let shdowimg = UIImage.setImageWithColor(LDGolbalColor.Green.colorWithAlphaComponent(1))
        
        //        navigationBar.shadowImage = UIImage()
        //        navigationBar.setBackgroundImage(image, forBarMetrics: UIBarMetrics.Compact)
        
        navigationBar.titleTextAttributes = [NSFontAttributeName : LDFont.Font16,NSForegroundColorAttributeName:LDGolbalColor.White]
        
        //左bar图
        
        barLeft = UIBarButtonItem(image: UIImage(named:"navBack.png"), style: UIBarButtonItemStyle.Plain, target: self, action:#selector(self.navBack))
        
    }
    
    override  func pushViewController(viewController: UIViewController, animated: Bool) {
        
        if tapPushClosure != nil {
            tapPushClosure!()
        }
        
        super.pushViewController(viewController, animated: true)
//        if self.childViewControllers.count > 0 {
//            
//            viewController.navigationItem.leftBarButtonItem = barLeft
//        }
        
        
        
    }
//    override func popViewControllerAnimated(animated: Bool) -> UIViewController? {
//        return super.popToRootViewControllerAnimated(true, complete: nil)
//    }
    
    //拦截pop事件
    func navBack(){
        
        if tapBackColure != nil {
            
            NSOperationQueue.mainQueue().addOperationWithBlock({ [weak self] in
                
                self?.tapBackColure!()
                self?.popViewControllerAnimated(true)
                
                })
            
        } else {
            
            popViewControllerAnimated(true)
        }
        
    }
    
    //返回回调
    func tapBackNavClosure(colusre:(()->Void)) {
        
        tapBackColure = colusre
        //        popViewControllerAnimated(true)
    }
    //push回调
    func tapPushNavClosure(colusre:(()->Void)?) {
        
        tapPushClosure = colusre
    }
    
    override  func preferredStatusBarStyle() -> UIStatusBarStyle {
        return UIStatusBarStyle.LightContent
    }
    
}
